<?php
require_once("../../config/config.inc.php");

$task = fn_getParam("task","");
if ($task == "logout") {
    $SEC->logout();
}

$feedback = "";
if ($task == "login") {
    $sUsername = fn_getParam("strUsername");
    $sPassword = fn_getParam("strPassword");
    $sVIPID    = fn_getParam("strVIPID",$USER_VIPID);

    $sStatus = $SEC->login($sVIPID,$sUsername,$sPassword);
    if ($sStatus == 0) {
?>
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
<HTML><HEAD>
<META http-equiv=content-type content='text/html; charset=UTF-8'/>
<META http-equiv=pragma content=no-cache>
<META http-equiv=expires content=0>
<TITLE>goodluck4u -- good luck for you</TITLE>
    <link rel="stylesheet" type="text/css" href='<?php echo $CFG_VIRT_JSCRIPT;?>/ext/resources/css/ext-all.css'/>
    <script type="text/javascript" src='<?php echo $CFG_VIRT_JSCRIPT;?>/ext/adapter/ext/ext-base.js'></script>
    <script type="text/javascript" src='<?php echo $CFG_VIRT_JSCRIPT;?>/ext/ext-all.js'></script>
    <script type="text/javascript" language="javascript">
        Ext.BLANK_IMAGE_URL = '<?php echo $CFG_VIRT_JSCRIPT;?>/ext/resources/images/default/s.gif';
    </script>
<style>
body,td { margin:2px;font:normal 12px tahoma, arial, sans-serif, 宋体;}

 .x-panel-body{
	background: url(<?php echo $CFG_VIRT_IMAGES;?>/bk.jpg);
	font: 12px Arial, Helvetica, sans-serif;
}
 .thumb{
	background: #dddddd;
	padding: 3px;
}
 .thumb img{
	height: 60px;
	width: 80px;
}
 .thumb-wrap{
	float: left;
	margin: 4px;
	margin-right: 0;
	padding: 5px;
}
 .thumb-wrap span{
	display: block;
	overflow: hidden;
	text-align: center;
    font-size:13px;
}

 .x-view-over{
    border:1px solid #dddddd;
    background: #efefef url(<?php echo $CFG_VIRT_JSCRIPT;?>/ext/resources/images/default/grid/row-over.gif) repeat-x left top;
	padding: 4px;
}

 .x-view-selected{
	background: #eff5fb url(<?php echo $CFG_VIRT_IMAGES;?>/outlook/selected.gif) no-repeat right bottom;
	border:1px solid #99bbe8;
    padding: 4px;
}
 .x-view-selected .thumb{
	background:transparent;
}
</style>
</head>

<body>
<div id="header">
Goodluck4u, 在线项目管理系统
</div>

<div id="footer">
<table width="100%" border="0" height="22">
<tr><td width="160" align="center"><div id="btnExitSystem"></div></td>
<td width="45%"> &nbsp; 
<?php echo $_SESSION["cfg_true_name"];?>，欢迎您登录系统，
上次登录时间是<?php echo $_SESSION["cfg_lastlogon_date"];?>。
</td><td align="right">
All right reservice, Goodluck4u.com CopyRight &copy; 2008-2009.  &nbsp; 
</td>
</tr></table>
</div>

<script language="javascript">
<!--
Ext.ux.TabRightMenu = function(){
    var tabs, menu, ctxItem;
    this.init = function(tp){
        tabs = tp;
        tabs.on('contextmenu', onContextMenu);
    }

    function onContextMenu(ts, item, e){
        if (!menu) { // create context menu on first right click
            menu = new Ext.menu.Menu([{
                id: tabs.id + '-reload',
                text: '刷新',
                icon: '../../images/btn/refresh.gif',
                handler : function(){
                    if (ctxItem.id == "tab-homepage") {
                        ctxItem.getUpdater().refresh();
                    } else {
                        var iframeID = ctxItem.id.replace("tab","if");
                        var frame = Ext.getDom(iframeID);
                        if (frame != null) frame.src = frame.src;
                    }
                }
            },'-',{
                id: tabs.id + '-close',
                text: '关闭',
                icon: '../../images/btn/close.gif',
                handler : function(){
                    if (ctxItem.id != "tab-homepage") tabs.remove(ctxItem);
                }
            },{
                id: tabs.id + '-close-others',
                text: '关闭其他',
                handler : function(){
                    tabs.items.each(function(item){
                        if (item.closable && item != ctxItem){
                            tabs.remove(item);
                        }
                    });
                }
            }]);
        }
        ctxItem = item;
        menu.items.get(tabs.id + '-close').setDisabled(!item.closable);
        var disableOthers = true;
        tabs.items.each(function(){
            if(this != item && this.closable){
                disableOthers = false;
                return false;
            }
        });
        menu.items.get(tabs.id + '-close-others').setDisabled(disableOthers);
        menu.showAt(e.getPoint());
    }
};


var btnExit = new Ext.Button({
    text: '退出系统',
    renderTo:'btnExitSystem',
    handler:function() {
        if (confirm("确定要退出系统？")) {
            window.location.href="./member.php?task=logout";
        }},
    icon: '../../images/btn/exit.gif',
    cls:"x-btn-text-icon"
});

/*menu dataview*/
var menuField = ['code','name','url','imagesrc','tip','upcode'];
var menuUrl = '<?php echo $CFG_WWWROOT;?>/apps/member/memuView.php?strUpCode=';

var menuTpl = new Ext.XTemplate(
    '<tpl for=".">',
        '<div class="thumb-wrap" id="{code}" title="{tip}">',
        '<div class="thumb"><img src="{imagesrc}"></div>',
        '<span>{name}</span></div>',
    '</tpl>'
);
function openTab(dv,node) {
    var record = dv.getRecord(node);
    var tabUrl = record.get("url");
    var menuCode = record.get("code");
    var tabTitle = record.get("name");
    var tabItem = tabSets.findById("tab-"+menuCode);
    if (tabItem==null) {
        tabItem = tabSets.add({id:"tab-"+menuCode, title:tabTitle,closable:true,
            html: '<iframe id="if-'+menuCode+'" src="'+tabUrl+'" width="100%" height="100%" frameborder="0"/>'});
    }
    tabItem.show();
}
function createDataView(upCode) {
    return new Ext.DataView({
        store: new Ext.data.JsonStore({autoLoad:true,root:'menus',fields:menuField,url:menuUrl+upCode}),
        tpl: menuTpl, singleSelect:true, overClass:'x-view-over', itemSelector:'div.thumb-wrap',
        listeners:{'click':function(dv,index,node,e) {openTab(dv,node);}}
    });
}
/*dataview end*/

var northPanel = new Ext.Panel({
    region:'north',
    contentEl: 'header',
    height:80,
    split:true,
    minSize:60,
    maxSize:120,
    collapsible:true,
    collapseMode:'mini'
});

var southPanel = new Ext.BoxComponent({
    region:'south',
    height:22,
    el:"footer"
});

var westPanel = new Ext.Panel({
    title:'功能菜单',
    layout:'accordion',
    region:'west',
    width:140,
    split:true,
    minSize:80,
    maxSize:160,
    collapsible:true,
    collapseMode:'mini',
    layoutConfig:{animate:true},
    items:[
    {title:'任务计划',border:false,autoScroll:true,items:createDataView("mm02")},
    {title:'图书文档',border:false,autoScroll:true},
    {title:'博客文章',border:false,autoScroll:true},
    {title:'消息管理',border:false,autoScroll:true,items:createDataView("mm04")},
    {title:'系统管理',border:false,autoScroll:true,items:createDataView("mm05")}]
});

var tabSets = new Ext.TabPanel({
    id:'tabset',
    region:'center',
    resizeTabs:true, // turn on tab resizing
    minTabWidth:100,
    tabWidth:120,
    activeTab:0,
    enableTabScroll:true,
    defaults: {autoScroll:true},
    plugins: new Ext.ux.TabRightMenu(),
    items:[{title:"首页",id:"tab-homepage",closable:false,
        autoLoad:"main.php"}]
});

var mainPanel = new Ext.Viewport({
    renderTo:Ext.getBody(),
    layout:'border',
    margins:'1 1 1 1',
    items:[northPanel,southPanel,westPanel,tabSets]
});

//-->
</script>

</body>
</html>
<?php
        return;
    } else if ($sStatus == 1) { 
        $feedback = "错误的用户名或密码，登录失败";
    } else if ($sStatus == 2) { 
        $feedback = "该VIP ID不存在，登录失败";
    } else if ($sStatus == 3) { 
        $feedback = "还处于申请状态，暂时不能登录";
    } else if ($sStatus == 4) { 
        $feedback = "该VIP ID已经被锁定，请与网站联系，登录失败";
    } else {
        $feedback = "未知错误，登录失败";
    }
}

if ($feedback != "") {
    $SM->assign("feedback","<font color=red>".$feedback."</font>");
}

//require the login page.
$SM->display('member/login.html');
?>
